$(document).ready(function(){
    $("#btn_send_captcha").click(function(){
        var email = $("#exampleInputEmail1").val();
        $this = $(this);   // button
        if(!email) {
            alert("请输入邮箱!");
        }else{
            
            // Ajax发送网络请求
            $.ajax(
                {
                    url: "/user/get_captcha",
                    method: "POST",
                    data: {
                        "email": email
                    },
                    success: function(res){
                        var status = res['code'];
                        if(status===200) {
                            // alert("验证码发送成功!");
                            $this.attr('disable', true);
                            var countDown = 60;
                            var timer = setInterval(function(){
                                if(countDown > 0) {
                                    $this.text(countDown+"秒后重新发送");
                                }else{
                                    $this.text("获取验证码");
                                    $this.removeAttr('disable');
                                    clearInterval(timer);   // ??? 清除倒计时

                                }
                                countDown = countDown - 1;
                                
                            }, 1000);
                        }else {
                            alert(res['message']);
                        }
                    }
                }
            );
        }
    });
})